package Simple.SearchTwoNum;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class SearchTwoNum2 {
    public static void main(String[] args) {
        int[] nums = new int[]{0,4,3,0};
        int target = 0;
        System.out.println(Arrays.toString(twoSum(nums, target)));
    }

    public static int[] twoSum(int[] nums, int target) {
        Map<Integer, Integer> resultMap = new HashMap<Integer, Integer>();
        for (int i = 0; i < nums.length; i++) {
            int complement = target - nums[i];
            if (resultMap.containsKey(complement)) {
                return new int[]{resultMap.get(complement), i};
            }
            resultMap.put(nums[i], i);
        }
        return new int[0];
    }
}
